import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:xcite/core/services/open_launcher.dart';

class JoinTeamDialog extends StatelessWidget {
  final VoidCallback? onJoinPressed;
  final VoidCallback? onCancelPressed;

  const JoinTeamDialog({super.key, this.onJoinPressed, this.onCancelPressed});

  @override
  Widget build(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Container(
          width: 320.w,
          margin: EdgeInsets.only(top: 40.h),
          padding: EdgeInsets.fromLTRB(24.w, 60.h, 24.w, 24.w),
          decoration: BoxDecoration(
            color: const Color(0xFFFDF5E1),
            borderRadius: BorderRadius.circular(20.r),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withValues(alpha: 0.15),
                blurRadius: 20.r,
                offset: Offset(0, 8.h),
              ),
            ],
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                constraints: BoxConstraints(maxWidth: 230.w),
                child: Text(
                  'Are you sure you want to join the current team?',
                  style: TextStyle(
                    fontSize: 20.sp,
                    fontFamily: 'PoetsenOne',
                    color: Colors.black,
                    height: 1.55,
                  ),
                  textAlign: TextAlign.center,
                ),
              ),

              SizedBox(height: 24.h),

              Column(
                children: [
                  GestureDetector(
                    onTap: onJoinPressed,
                    child: SizedBox(
                      height: 56.h,
                      child: AspectRatio(
                        aspectRatio: 204 / 56,
                        child: Image.asset(
                          'assets/resources/confirm_button.png',
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                  ),

                  SizedBox(height: 12.h),

                  GestureDetector(
                    onTap: onCancelPressed,
                    child: SizedBox(
                      height: 56.h,
                      child: AspectRatio(
                        aspectRatio: 204 / 56,
                        child: Image.asset(
                          'assets/resources/cancel_button.png',
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                  ),
                ],
              ),

              SizedBox(height: 16.h),

              GestureDetector(
                onTap: () => _showEula(context),
                child: Text(
                  'EULA',
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: Colors.black,
                    decoration: TextDecoration.underline,
                    decorationColor: Colors.black,
                  ),
                ),
              ),
            ],
          ),
        ),
        Positioned(
          top: -80.h,
          left: 0,
          right: 0,
          child: Center(
            child: SizedBox(
              width: 230.w,
              height: 195.h,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(40.r),
                child: Image.asset(
                  'assets/resources/flower_dialog.png',
                  width: 230.w,
                  height: 195.h,
                  fit: BoxFit.contain,
                  errorBuilder: (context, error, stackTrace) {
                    return Container(
                      width: 80.w,
                      height: 80.h,
                      decoration: BoxDecoration(
                        color: const Color(0xFF2AB061),
                        borderRadius: BorderRadius.circular(40.r),
                      ),
                      child: Icon(
                        Icons.group_outlined,
                        size: 40.sp,
                        color: Colors.white,
                      ),
                    );
                  },
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }

  void _showEula(BuildContext context) {
    Open.openLaunch(
      'https://www.freeprivacypolicy.com/live/2908db45-eaa5-4be2-bf12-428f9bbadb26',
    );
  }
}
